<%@page import="helper.UtilFunction"%>
<%@page import="beans.Account"%>
<%@page import="java.util.List"%>
<%@page import="dao.CheckAccount"%>
<%@page import="dao.MngClass"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            if (request.getAttribute("msg") != null) {
        %>
        <font color="green" > <%= request.getAttribute("msg")%> </font>
        <%
            }
             if (request.getAttribute("error") != null) {
        %>
        <font color="red" > <%= request.getAttribute("error")%> </font>
        <%
            }
        
            MngClass mngClass = new MngClass();
            CheckAccount ck = new CheckAccount();
            List<Account> listStudent = ck.listAccByRoll("student");
            List<Account> listStudying = ck.listAccByClassId(request.getAttribute("class_id").toString());
            UtilFunction util = new UtilFunction();
        %>
        <form action="addStudentInClass" method="get">
            Student : <select name="acc_id">
                <option value="">Select Student</option> 
                <%
                    for (Account acc_all : listStudent) {
                        if (listStudying != null && listStudying.size() > 0) {
                            if (util.studentOutClass(listStudying, acc_all.getAcc_id())) {
                %>
                <option value="<%= acc_all.getAcc_id()%>"><%= acc_all.getUser_name()%></option> 
                <%
                    }
                } else {
                %>
                <option value="<%= acc_all.getAcc_id()%>"><%= acc_all.getUser_name()%></option> 
                <%
                        }
                    }
                %>
            </select><font color="red" >*</font>
            <br>Class   : <%= mngClass.getClassName(request.getAttribute("class_id").toString())%>
            <input type="hidden" name="class_id" value="<%= request.getAttribute("class_id").toString()%>">
            <br> <input type="submit" value="Add Student">
        </form>    
    </body>
</html>
